package edu.action;



import java.util.List;
import com.opensymphony.xwork2.ActionSupport;

import edu.model.Patient;
import edu.service.PatientService;


public class PatientAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2116833997089520571L;
	
	private int	patientId = 0;

	private String	patientName;
	private String	patientDoc;
	private String	patientAdd;
	private String	patientOffice;
	private String	patientTel;
	private String	patientZip;
	private int	patientSex;
	private String	personId;
	private int	patientAge;
	
	
	private Patient patient = null;
	private List<Patient> patientList = null;
	
	private PatientService patientService = null;
	
	public int getPatientId() {
		return patientId;
	}

	public void setPatientId(int patientId) {
		this.patientId = patientId;
	}
	

	public String getPatientName() {
		return patientName;
	}

	public void setPatientName(String patientName) {
		this.patientName = patientName;
	}

	public String getPatientAdd() {
		return patientAdd;
	}

	public void setPatientAdd(String patientAdd) {
		this.patientAdd = patientAdd;
	}

	public String getPatientOffice() {
		return patientOffice;
	}

	public void setPatientOffice(String patientOffice) {
		this.patientOffice = patientOffice;
	}

	public String getPatientTel() {
		return patientTel;
	}

	public void setPatientTel(String patientTel) {
		this.patientTel = patientTel;
	}

	public String getPatientZip() {
		return patientZip;
	}

	public void setPatientZip(String patientZip) {
		this.patientZip = patientZip;
	}

	public int getPatientSex() {
		return patientSex;
	}

	public void setPatientSex(int patientSex) {
		this.patientSex = patientSex;
	}

	public int getPatientAge() {
		return patientAge;
	}

	public void setPatientAge(int patientAge) {
		this.patientAge = patientAge;
	}

	public String getPersonId() {
		return personId;
	}

	public void setPersonId(String personId) {
		this.personId = personId;
	}

	public String getPatientDoc() {
		return patientDoc;
	}

	public void setPatientDoc(String patientDoc) {
		this.patientDoc = patientDoc;
	}

	public Patient getPatient() {
		return patient;
	}

	public List<Patient> getPatientList() {
		return patientList;
	}

	public void setPatientList(List<Patient> patientList) {
		this.patientList = patientList;
	}

	public void setPatient(Patient patient) {
		this.patient = patient;
	}
	
	public PatientService getPatientService() {
		return patientService;
	}

	public void setPatientService(PatientService patientService) {
		this.patientService = patientService;
	}

	public String detail(){
		patient = patientService.getPatientById(patientId);
		
		if(patient != null){
			System.out.println(patient.getPatientName());
			return SUCCESS;
		}
		return ERROR;
	}
	public String list(){
		patientList = patientService.getAllPatient();
		return SUCCESS;
	}
	public String add(){
		System.out.println(patientName + " " + personId);
		
		Patient patient = new Patient();
		patient.setPatientName(patientName);
		patient.setPatientDoc(patientDoc);
		patient.setPatientSex(patientSex);
		patient.setPatientAdd(patientAdd);
		patient.setPatientAge(patientAge);
		patient.setPatientOffice(patientOffice);
		patient.setPatientTel(patientTel);
		patient.setPatientZip(patientZip);
		patient.setPersonId(personId);
		
		patientService.savePatient(patient);
		patientId = patient.getPatientId();
		
		return SUCCESS;
	}
	
	public String edit(){
	
		Patient patient = patientService.getPatientById(patientId);
		if(patient != null) {
			patient.setPatientName(patientName);
			patient.setPatientDoc(patientDoc);
			patient.setPatientSex(patientSex);
			patient.setPatientAdd(patientAdd);
			patient.setPatientAge(patientAge);
			patient.setPatientOffice(patientOffice);
			patient.setPatientTel(patientTel);
			patient.setPatientZip(patientZip);
			patient.setPersonId(personId);
			
			patientService.updatePatient(patient);
			return SUCCESS;
		}
		return ERROR;
	}
	
	public String show(){
		patient = patientService.getPatientById(patientId);
		if(patient != null) {
			return SUCCESS;
		}
		return ERROR;
	}
}
